package com.lcq.userscenter.users.service.impl;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import com.lcq.userscenter.common.util.ConstatFinalUtil;
import com.lcq.userscenter.common.util.PageInfoUtil;
import com.lcq.userscenter.users.dao.IAAdminsDao;
import com.lcq.userscenter.users.pojo.AAdmins;
import com.lcq.userscenter.users.service.IUsersService;
/**
 * 用户相关的Service实现类
 * 
 * @author ASUS_LCQ
 *
 */
@Service("usersService")
public class UsersServiceImpl implements IUsersService
{
	@Resource
	private IAAdminsDao adminsDao;
	
	/**
	 * 查询一条管理员记录
	 */
	@Override
	public AAdmins findOneAdminsService(Map<String, Object> condMap)
	{
		return this.adminsDao.findOne(condMap);
	}
	/**
	 * 添加一条管理员记录
	 */
	@Override
	public JSONObject saveOneAdminsService(AAdmins admins)
	{
		JSONObject resultJSON = new JSONObject();
		/* 影响条数 */
		int res = this.adminsDao.save(admins);
		/*String str = null ; 
		str.toString();*/
		if(res > 0 )
		{
			resultJSON.put("code", "0");
			resultJSON.put("info", ConstatFinalUtil.INFO_JSON.get("0"));
			/* 存储data */
			JSONObject dataJSON = new JSONObject();
			dataJSON.put("id", admins.getId() + "");
			dataJSON.put("effect", res + "");
			
			resultJSON.put("data", dataJSON);
		}else
		{
			resultJSON.put("code", "1");
			resultJSON.put("info", ConstatFinalUtil.INFO_JSON.get("1"));
		}
		return resultJSON;
	}
	
	/**
	 * 更新一条管理员信息
	 */
	@Override
	public JSONObject updateOneAdminsService(AAdmins admins)
	{
		JSONObject resultJSON = new JSONObject();
		/*影响条数*/
		int res = this.adminsDao.update(admins);
		if(res > 0)
		{
			resultJSON.put("code", "0");
			resultJSON.put("info", "成功");
			/*存储data*/
			JSONObject dataJSON = new JSONObject();
			dataJSON.put("id", admins.getId()+"");
			dataJSON.put("effect", res + "");
			resultJSON.put("data", dataJSON);
		}else
		{
			resultJSON.put("code", "2");
			resultJSON.put("info", ConstatFinalUtil.INFO_JSON.get("2"));
		}
		return resultJSON;
	}
	
	/**
	 * 删除一条管理员记录
	 */
	@Override
	public JSONObject deleteOneAdminsService(AAdmins admins)
	{
		JSONObject resultJSON = new JSONObject();
		/*影响条数*/
		int res = this.adminsDao.delete(admins);
		if(res > 0)
		{
			resultJSON.put("code", "0");
			resultJSON.put("info", "成功");
			/*存储data*/
			JSONObject dataJSON = new JSONObject();
			dataJSON.put("id", admins.getId()+"");
			dataJSON.put("effect", res + "");
			resultJSON.put("data", dataJSON);
		}else
		{
			resultJSON.put("code", "3");
			resultJSON.put("info", ConstatFinalUtil.INFO_JSON.get("3"));
		}
		return resultJSON;
	}
	/*
	@Override
	public List<AAdmins> findCondListAdminsService(PageInfoUtil pageInfoUtil, Map<String, Object> condMap)
	{
		为关键字加上%,实现模糊匹配
		if(condMap.get("keyword") != null && !"".equalsIgnoreCase(condMap.get("keyword")+""))
		{
			condMap.put("keyword", "%" + condMap.get("keyword")+"%");
		}
		if (pageInfoUtil != null)
		{
			分页
			 * 查询总记录数
			 * 
			condMap.put("pageCount", "true");
			List<AAdmins> roleList = this.adminsDao.findCondList(condMap);
			取总记录数
			if (roleList.size() == 1)
			{
				pageInfoUtil.setTotalRecord(roleList.get(0).getId());
			}
		}
		return null;
	}*/


}
